package rtcf.framework
{
	import flash.net.NetConnection;
	import flash.net.SharedObject;
	import flash.utils.Proxy;
	import flash.utils.flash_proxy;
	
	use namespace flash_proxy;

	public dynamic class RTCFSharedObject extends Proxy
	{
		
		private var sharedObject:SharedObject;
		private var netConnection:NetConnection;
		
		public function RTCFSharedObject(so:SharedObject, nc:NetConnection)
		{
			sharedObject = so;
			netConnection = nc;
		}
		
		public function connect(... args:Array):void{
			args.unshift(netConnection);
			sharedObject.connect.apply(sharedObject, args);
		}
		
		
		//// ---- ---- Proxy methods ---- ---- ////
		
		/**
		 * 
		 */
		override flash_proxy function getProperty(name:*):*
		{
			
			return sharedObject[name];
		}
		
		/**
		 *
		 */
		override flash_proxy function setProperty(name:*, value:*):void
		{
			sharedObject[name] = value;
		}
		
		/**
		 *
		 */
		override flash_proxy function callProperty(name:*, ... args:Array):*
		{
			return sharedObject[name].apply(sharedObject, args);
		}
		
		//used to store the nextName values
		private var nextNameArray:Array;
		
		
		/**
		 * 
		 */
		override flash_proxy function nextNameIndex(index:int):int
		{/*
			if (index == 0)
			{
			nextNameArray = [];
			for (var op:String in _operations)
			{
			nextNameArray.push(op);    
			}    
			}
			return index < nextNameArray.length ? index + 1 : 0;
			*/
			return 0;
		}
		
		/**
		 * 
		 */
		override flash_proxy function nextName(index:int):String
		{
			/*
			return nextNameArray[index-1];
			*/
			return 'hi';
		}
		
		/**
		 * 
		 */
		override flash_proxy function nextValue(index:int):*
		{
			//return _operations[nextNameArray[index-1]];
			return null;
		}
		
		private function getLocalName(name:Object):String
		{
			/*
			if (name is QName)
			{
			return QName(name).localName;
			}
			else
			{
			return String(name);
			}
			*/
			return null;
		}		
	}
}